<?php
	include_once 'isLogin.php';
	require_once("../model/push.class.php");
	$table_name = "informations";
	$table_chanl="informations_channels";
	if($_POST['submit']){
		//编辑状态先获得原内容
		//编辑状态先获得原内容
		if($_GET['id']!=false){
			$old = $commonc->getInfo($table_name,$_GET['id'],'img');
			$img = $old['img'];
		}
		//上传图片，生成缩略图
		if($_FILES['img']['name']!=''){
			//设置路径
			$folder="upload/image/";
			$annexFolder = $folder."large/";
			$middleFolder = $folder."middle/";
			$smallFolder = $folder."small/";
			//删除旧图
			@unlink($annexFolder.$img);
			@unlink($middleFolder.$img);
			@unlink($smallFolder.$img);
			//上传新图
			$upimg = new uploadImg();
			$img = $upimg->upLoad('img',$annexFolder);
			//中图
			$upimg->smallImg($annexFolder.$img,$middleFolder);
			//小图
			$upimg->smallImg($annexFolder.$img,$smallFolder);
		}
		//插入数据库
		$data = array('title'=>$_POST['title'],'simtitle'=>$_POST['simtitle'],'content'=>$_POST['content'],'sort'=>$_POST['sort'],'type'=>$_POST['type'],'img'=>$img,'author'=>$_POST['author'],'froms'=>$_POST['froms'],'date'=>date('Y-m-d',time()),'channel_id'=>$_POST['channel']);
		if($_GET['id']!=false){
			$commonc->update($table_name,$data,"id='".$_GET['id']."'");
			$href = $_basename.'?id='.$_GET['id'];
		}else{
			$res=$commonc->insert($table_name,$data);
			$href='information_add.php';
			$id = $commonc->insert_id();
			if($res){
				
				$mess=new messagePush();
				$mess->backMessage($_POST['content'],$_POST['title'],$id);
				
			}
			$data = array('sort'=>$id);
			$commonc->update($table_name, $data, "id='".$id."'");
		
		}
		echo $commonc->submitAlert('成功',$href);
	}
	//获取频道信息
	$sqll=$table_chanl;
	$res=$commonc->getList($sqll, $sqlnum='', $key="id,title",$debug='0');
	//获得数据
	if($_GET['id']!=false){
		$row=$commonc->getInfo($table_name,$_GET['id']);
		$smarty->assign('row',$row);
		$smarty->assign('area',$area);
	}
        
	$smarty->assign('res',$res['result']);
	$smarty->display($_filename.".html");
	
?>